// Copyright (C) 2025, ZWSOFT Co., LTD.(Guangzhou)
// Licensed under the MIT License. See LICENSE in the project root for license information.

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Collections.ObjectModel;
using TestClient.Domain;

namespace TestClient.ViewModel;
public partial class CurveIntersectTestViewModel : PageViewModelBase
{

    public ObservableCollection<string> Result { get; } = [];

    [ObservableProperty]
    private string curveId = "";

    public IAsyncRelayCommand SelectCurveCommand { get; }
    public IAsyncRelayCommand InquireCommand { get; }

    public CurveIntersectTestViewModel(VFAdapterWrapper wrapper, ISnackNotifyService notifyService)
        : base(wrapper, notifyService)
    {
        SelectCurveCommand = CreateAsyncRpcCommand(SelectCurve);
        InquireCommand = CreateAsyncRpcCommand(Inquire);
    }

    private async Task SelectCurve()
    {
        EnsureConnected();
        CurveId = await ViewModelHelpers.SelectEnt(Wrapper, "Curve");
    }
    private async Task Inquire()
    {
        EnsureConnected();
        var list = await Task.Run(() =>
        {
            return Wrapper.GetIntersectCurve(CurveId);
        });
        Result.Clear();
        foreach (var item in list)
        {
            Result.Add(item);
        }
    }
}
